﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace schedule
{
    public partial class PublicScheduleForm : Form
    {
        private String categoryName;

        private WorkInfo cWorkInfo = new WorkInfo();

        public PublicScheduleForm(String categoryName)
        {
            InitializeComponent();
            this.categoryName = categoryName;
            loadData();
        }

        public void loadData()
        {
            WorkManager wm = WorkManager.Instance();
            foreach (WorkInfo wi in wm.workinfoList)
            {
               
                if ((wi.category == categoryName) && (wi.isPublic == true))
                {
                    dataGridView1.Rows.Add(wi.owner, wi.title, wi.startTime.ToString());
                }
            }
        }

        private void dataGridView1_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            MakeForm f = new MakeForm(true);
            
            
            String selectedRowsWriter = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
            String selectedRowsTitle = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
            String selectedRowsDate = dataGridView1.SelectedRows[0].Cells[2].Value.ToString();

            WorkManager wm = WorkManager.Instance();
            foreach (WorkInfo wi in wm.workinfoList)
            {
                if ((wi.owner == selectedRowsWriter) && (wi.title == selectedRowsTitle))
                {
                    cWorkInfo = wi;
                }
            }

            f.editContent(cWorkInfo);
            if (f.ShowDialog() == DialogResult.OK)
            {
                this.Close();
            }


        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }


    }
}
